package com.temp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.temp.dto.RobotCampaignDTO;
import com.temp.dto.SearchCampaignDTO;
import com.temp.dto.SetCampaignDTO;
import com.temp.entity.Campaign;
import com.temp.vo.CampaignDataVO;
import com.temp.vo.CampaignDetailVO;
import com.temp.vo.CampaignStatusVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CampaignMapper extends BaseMapper<Campaign> {

    @Select("SELECT c.id, c.status, d.amount, d.user_id as donation_user_id FROM campaign_view c LEFT JOIN donation d ON c.id = d.campaign_id WHERE c.user_id = #{userId}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "status", column = "status"),
            @Result(property = "amount", column = "amount"),
            @Result(property = "donationUserId", column = "donation_user_id")
    })
    List<CampaignDataVO> findCampaignDataByUserId(@Param("userId") Long userId);

    CampaignStatusVO findCampaignById(@Param("id") Long id);

    List<CampaignStatusVO> findCampaignByStatus(SearchCampaignDTO campaignDTO);

    List<CampaignDetailVO> findCampaignDetail(SearchCampaignDTO campaignDTO);

    Integer findAllNotEndedCampaign(Long userId);

    Integer countCampaignDetail(SearchCampaignDTO campaignDTO);

    Integer updateCampaignSet(SetCampaignDTO campaignDTO);

    @Select("SELECT * FROM campaign WHERE id = #{id} FOR UPDATE")
    Campaign getCampaignForUpdate(Long id);

    List<Campaign> findAllCampaignByRobot(RobotCampaignDTO robotCampaignDTO);
}
